#pragma once


#include "scene/Scene.hpp"
#include "math/Random.hpp"
#include "trace/Ray.hpp"
#include "Color.hpp"


class Tracer
{
public:
    Tracer() {};

    Color trace(const Scene& scene, const Ray& ray, int depth)
    {
        if (depth <= 0)
        {
            // return background color
            return Color(0.5, 0.5, 0.5);
        }

        std::unique_ptr<HitResult> pHitResult = scene.hitTest(ray);
        if (pHitResult == nullptr)
        {
            // return background color
            return Color(0.5, 0.5, 0.5);
        }
        else
        {
            // reflection direction for now
            Ray newRay(
                pHitResult->point(),
                pHitResult->normal() + _randomUnitVector.next());

            // object material for now
            return Color(0.5f, 0.5f, 0.5f, 1.0f) * trace(scene, newRay, depth - 1);
        }
    }

private:
    RandomUnitVector _randomUnitVector;
};
